﻿using System;
using System.Windows.Forms;
using mfe.bll;
using System.Collections.Generic;
using System.Data.SQLite;
using System.Data;

namespace mfe_proj
{
    public delegate void TestFormEventHandler(object sender, TestFormEventArgs e);

    public partial class TestForm : Form
    {
        public event TestFormEventHandler DoubleClicked;
        public TestForm()
        {
            InitializeComponent();
        }

        private void TestForm_Load(object sender, EventArgs e)
        {
            //LoadData();

            SQLiteConnection conn = new SQLiteConnection(@"Data Source=D:\test2.s3db;Pooling=true;FailIfMissing=false");
            conn.Open();
            try
            {
                SQLiteCommand cmd = new SQLiteCommand();
                cmd.CommandType = CommandType.Text;
                cmd.Connection = conn;
                cmd.CommandText = "select id, title from test";
                SQLiteDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    listBox1.Items.Add(reader["title"].ToString());
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            finally
            {
                conn.Clone();
                conn.Dispose();
            }
        }

        public void LoadData()
        {
            //List<Item> items = Item.ItemCollection();
            //foreach (Item item in items)
            //{
            //    listBox1.Items.Add(item);
            //}
        }

        void Document_ContextMenuShowing(object sender, HtmlElementEventArgs e)
        {
            
        }

        private void listBox1_DoubleClick(object sender, EventArgs e)
        {
            //if (listBox1.SelectedIndices.Count > 0)
            //{
            //    Forms.AuthorForm authorForm = new mfe_proj.Forms.AuthorForm();
            //    authorForm.ItemGuidID = ((Item)listBox1.SelectedItem).ItemGuidID;
            //    authorForm.ShowDialog();
            //}

            if (DoubleClicked != null)
                DoubleClicked(sender, new TestFormEventArgs(((Item)listBox1.SelectedItem).ItemGuidID));
        }

        public Panel DockablePanel
        {
            get { return panel1; }
            set { panel1 = value; }
        }
    }

    public class TestFormEventArgs : EventArgs
    {
        public string _ItemGuidID;
        public TestFormEventArgs(string itemGuidID)
        {
            _ItemGuidID = itemGuidID;
        }
    }
}
